package com.andy.buyu.server.action;

import org.springframework.stereotype.Component;

import com.andy.buyu.server.entity.UsrGameLog;
import com.andy.buyu.server.game.GameUser;
import com.andy.buyu.server.socket.GmAction;
import com.andy.buyu.server.socket.MySocketSession;
import com.andy.buyu.server.socket.SendUtil;
import com.andy.buyu.server.socket.codec.DataWrap;
import com.andy.buyu.server.utils.CommonUtils;
import com.andy.buyu.server.utils.GoConstant;

/**
 * 锁定攻击
 * @author cuiwm
 *
 */
@Component(GmAction.ACTION_PREFIX+GmAction.ACTION_206)
public class Action206 implements IReqAction{

	@Override
	public void doAction(MySocketSession session, DataWrap data) {
		GameUser user = session.getUser();
		int scriptId = data.getInt();
		
		if(user.getBattery() != GoConstant.BATTERY_TYPE_1) return;
		boolean isFire = CommonUtils.fire(user, scriptId, 0, 0,GoConstant.BATTERY_TYPE_1);
		if(!isFire) return;
		// 锁定炮必然打中，同时执行捕鱼逻辑
		UsrGameLog log = CommonUtils.catchFish(user, user.getGame(), scriptId, GoConstant.BATTERY_TYPE_1,0);
		if(log != null && log.getRate() >= 0){
			if(log.battary() > 0){
				SendUtil.send202(user.getRoom(),GoConstant.BATTERY_TYPE_1, log,user);
				// 由前端触发
//				SendUtil.send203(user);
			}else {
				SendUtil.send202(user.getRoom(),GoConstant.BATTERY_TYPE_1, log,null);
			}
		}
		
	}


	
	
	
}
